package cn.micai.base.string;

/**
 * 描述：反转字符串的Java程序
 * <p> Using recursion(递归)
 *
 * @author: 赵新国
 * @date: 2018/6/11 11:28
 */
public class ReverseStringRecursive {

    public static void main(String [] args) {

        ReverseStringRecursive reverseStringRecursive = new ReverseStringRecursive();
        String blogName = "java2blog";
        String reverse = reverseStringRecursive.recursiveReverse(blogName);
        System.out.println("Reverse of java2blog is:"+reverse);

    }

    public String recursiveReverse(String orig) {
        if (orig.length() == 1) {
            return orig;
        } else {
            return orig.charAt(orig.length()-1) + recursiveReverse(orig.substring(0, orig.length()-1));
        }
    }
}
